package org.springframework.beans.factory.context;

import org.springframework.beans.factory.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.beans.factory.support.AnnotationConfigRegistry;
import org.springframework.beans.factory.util.Objects;


/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/12/13
 */
public class AnnotationApplicationContext extends GenericApplicationContext implements AnnotationConfigRegistry {

    private final AnnotatedBeanDefinitionReader reader;

    public AnnotationApplicationContext(){
        //会去调用GenericApplicationContext的构造方法实例化bean工厂
        //注解bd读取器
        this.reader = new AnnotatedBeanDefinitionReader(this);
    }

    public AnnotationApplicationContext(Class<?>... annotatedClasses){
        //实例化bean工厂，注册三个bd
        this();
        //注册config bd
        register(annotatedClasses);

        refresh();
    }

    @Override
    public void register(Class<?>... annotatedClasses) {
        Objects.noEmpty(annotatedClasses,"At least one annotated class must be specified");
        this.reader.register(annotatedClasses);
    }
}
